package com.example.demo.controller;

import com.example.demo.dto.ResponseResult;
import com.example.demo.dto.LoginRequestDTO;
import com.example.demo.service.UserService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * 模拟登录
 */
@RestController
public class LoginController {


    @Resource
    private UserService userService;


    /**
     * 登录
     * <p>
     * 布尔类型变量和前端交互时采用 0 或 1
     *
     * @param request
     * @return 登录结果：0-失败；1-成功
     */
    @PostMapping("/doLogin")
    public ResponseResult<Integer> doLogin(@Validated @RequestBody LoginRequestDTO request) {
        int result = userService.doLogin(request);
        return ResponseResult.buildSuccess(result);
    }

}
